package com.flow.asyncflow.core.entity.core;

import com.flow.asyncflow.core.entity.config.AsyncFlowInfo;
import com.flow.asyncflow.core.entity.log.asyncflowlog.AsyncFlowNodeDetailLogEntity;
import com.flow.asyncflow.core.entity.log.asyncflowlog.AsyncFlowNodeLogEntity;
import com.flow.asyncflow.core.entity.log.businesslog.AsyncFlowBusinessLogEntity;
import com.flow.asyncflow.core.entity.sql.ExecuteSql;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 异步流上下文（工作台）
 */
@Data
public class AsyncFlowBaseContext {

    /**
     * 节点日志
     */
    private List<AsyncFlowNodeLogEntity> asyncFlowNodeLogEntityList = Collections.synchronizedList(new ArrayList<>());
    /**
     * 节点明细日志【AsyncFlowCommon_Log.AddAsyncFlowDetailLog()放在此集合中】
     */
    private List<AsyncFlowNodeDetailLogEntity> asyncFlowNodeDetailLogEntityList = Collections.synchronizedList(new ArrayList<>());
    /**
     * 业务日志【AsyncFlowBusinessLog.addBusinessLog()放在此集合中】
     */
    private List<AsyncFlowBusinessLogEntity> asyncBusinessLogEntityList = Collections.synchronizedList(new ArrayList<>());
    /**
     * 需要执行的sql【AsyncFlowBuildSql类中的各个方法生成的SQL语句放在此集合中】
     */
    private List<ExecuteSql> executeSQLs = Collections.synchronizedList(new ArrayList<>());
    /**
     * 数据源（从数据库中查询出来的 ;表名-具体实体）【数据库冲查出的所有实体】
     */
    private ConcurrentHashMap<String, Object> dataMap = new ConcurrentHashMap<>();
    /**
     * 数据库名称和数据库的SessionFactory
     */
    private Map<String, String> dataBaseInfo = new HashMap<>();
    /**
     * 节点流信息
     */
    private AsyncFlowInfo asyncFlowInfo = null;

    /**
     * 测试上下文【在本地测试环境，使用显示的测试数据测试时才有值】
     */
    private String TESTContext;
    /**
     * 测试请求参数【在本地测试环境，使用显示的测试数据测试时才有值】
     */
    private String TESTRequest;

    /**
     * @param clazz
     * @param <T>
     * @return
     */
    public <T> T getDBData(Class<T> clazz) {
        T result = null;

        Object data = this.dataMap.get(clazz.getName());
        if (data != null ) {
            result = (T) data;
        }
        return result;
    }


}
